Skip to content

RegexPatternValidator

Base classes

Name Children Inherits
Validator
prettyqt.gui.validator

⋔ Inheritance diagram

graph TD
  2169721227["validators.RegexPatternValidator"]
  422589614["gui.Validator"]
  1804432572["gui.ValidatorMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  49520861["QtGui.QValidator"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  422589614 --> 2169721227
  1804432572 --> 422589614
  3227531497 --> 1804432572
  2751680898 --> 3227531497
  49520861 --> 422589614
  3984060476 --> 49520861
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: Validator

Validator which checks whether given string is a parseable regex pattern.

Source code in prettyqt/validators/regexpatternvalidator.py
class RegexPatternValidator(gui.Validator):
    """Validator which checks whether given string is a parseable regex pattern."""

    ID = "regex_pattern"
    error_occured = core.Signal(str)
    pattern_updated = core.Signal(object)

    def __repr__(self):
        return get_repr(self)

    def __eq__(self, other: object):
        return isinstance(other, type(self))

    def validate(  # type: ignore
        self, text: str, pos: int = 0
    ) -> tuple[gui.QValidator.State, str, int]:
        # if text == "":
        #     self.compiled = None
        #     return (self.Intermediate, text, pos)
        try:
            compiled = re.compile(text)
        except sre_constants.error as e:
            self.error_occured.emit(str(e))
            self.pattern_updated.emit(None)
            return self.State.Intermediate, text, pos
        else:
            self.error_occured.emit("")
            self.pattern_updated.emit(compiled)
            return self.State.Acceptable, text, pos

:fa-brands-github: Show source on GitHub